package com.tanhua.server.controller;

import com.tanhua.model.vo.TestResultVo;
import com.tanhua.model.vo.TestSoulVo;
import com.tanhua.server.service.TestSoulService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/testSoul")
public class TestSoulController {


    @Autowired
    private TestSoulService testSoulService;

    /**
     *      查询测试列表
     * @return
     */
    @GetMapping
    public ResponseEntity getTestSoul(){
        List<TestSoulVo> testSoul = testSoulService.getTestSoul();
        return ResponseEntity.ok(testSoul);
    }

    /**
     *      接收测试结果
     * @param answers
     * @return
     */
    @PostMapping
    public String answers(@RequestBody Map<String,List> answers){
        String id = testSoulService.answers(answers);

        return id;
    }

    /**
     *      查询测试结果
     * @param id
     * @return
     */
    @GetMapping("/report/{id}")
    public ResponseEntity Report(@PathVariable Integer id){
        System.out.println("id = " + id);
        TestResultVo result = testSoulService.getReport(id);

        return ResponseEntity.ok(result);
    }
}
